/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package glamourbeautyclinic;

import glamourbeautyclinic.cashier.FrmBill;
import glamourbeautyclinic.cashier.FrmSearchBill;
import glamourbeautyclinic.customer.FrmAppointment;
import glamourbeautyclinic.customer.FrmCustomer;
import glamourbeautyclinic.customer.FrmSearchApp;
import glamourbeautyclinic.personel.FrmStaff;
import glamourbeautyclinic.service.FrmCate_Service;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import images.GlamourImage;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MenuItem;
import java.io.BufferedReader;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import util.DBConnection;
import util.Utility;

/**
 *
 * @author anh
 */
public class FrmHome extends javax.swing.JFrame {
    
    GlamourImage GI = new GlamourImage();
    Utility util = new Utility();
    public DBConnection dc;
    public JInternalFrame  fLogin, fChangePass, fConfig, fAccount,
            fCate_Ser, fSerApp, fStaff, fStaffApp, fCust, fApp, 
            fSearchApp, fBill, fSearchBill;
    
    public String user = "anhpt";
    String role = "administrator";
    
    /**
     * Creates new form frmHome
     */
    public FrmHome() {
        initComponents();
        
        GI.addIconFor(this);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration());
        int taskBarSize = scnMax.bottom;
        this.setBounds(0, 0, screenSize.width, screenSize.height - taskBarSize);
        desk.putClientProperty("JDesktopPane.dragMode", "outline");
        
        getCon("Setting/Config.dat");
    }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desk = new javax.swing.JDesktopPane(){
		ImageIcon icon = new ImageIcon(GI.getClass().getResource("background.png"));
    Image image = icon.getImage();

    Image newimage = image.getScaledInstance(1500, 1000, Image.SCALE_SMOOTH);

    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.drawImage(newimage, 0, 0, this.getWidth(), this.getHeight(),this);
    }
	   };

        jPanel1 = new javax.swing.JPanel(){
		ImageIcon icon = new ImageIcon(GI.getClass().getResource("plastic.jpg"));
    Image image = icon.getImage();

    Image newimage = image.getScaledInstance(1500, 1000, Image.SCALE_SMOOTH);

    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.drawImage(newimage, 0, 0, this.getWidth(), this.getHeight(),this);
    }
	   };

        lblUser = new javax.swing.JLabel();
        lblUserDetail = new javax.swing.JLabel();
        lblRole = new javax.swing.JLabel();
        lblRoleDetail = new javax.swing.JLabel();
        lblLoginAt = new javax.swing.JLabel();
        lblLoginAtDetail = new javax.swing.JLabel();
        mbrMain = new javax.swing.JMenuBar();
        mnuHome = new javax.swing.JMenu();
        mniLogIn = new javax.swing.JMenuItem();
        mniChangePass = new javax.swing.JMenuItem();
        mniLogOut = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mniMaAcc = new javax.swing.JMenuItem();
        mniConfig = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        mniQuit = new javax.swing.JMenuItem();
        mnuCust = new javax.swing.JMenu();
        mniMaCust = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        mniMaApp = new javax.swing.JMenuItem();
        mniSeApp = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        mniCustDepReport = new javax.swing.JMenuItem();
        mnuSer = new javax.swing.JMenu();
        mniMaCat = new javax.swing.JMenuItem();
        mniSerDeptReport = new javax.swing.JMenuItem();
        mnuPer = new javax.swing.JMenu();
        mniMaSta = new javax.swing.JMenuItem();
        mnuCash = new javax.swing.JMenu();
        mniMaBill = new javax.swing.JMenuItem();
        mniSeBill = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        mniCashDeptReport = new javax.swing.JMenuItem();
        mnuAbout = new javax.swing.JMenu();
        mniAuthor = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        desk.setBackground(new java.awt.Color(204, 204, 204));
        desk.setPreferredSize(new java.awt.Dimension(400, 260));

        javax.swing.GroupLayout deskLayout = new javax.swing.GroupLayout(desk);
        desk.setLayout(deskLayout);
        deskLayout.setHorizontalGroup(
            deskLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 657, Short.MAX_VALUE)
        );
        deskLayout.setVerticalGroup(
            deskLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 458, Short.MAX_VALUE)
        );

        getContentPane().add(desk, java.awt.BorderLayout.CENTER);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setMaximumSize(new java.awt.Dimension(32767, 30));
        jPanel1.setMinimumSize(new java.awt.Dimension(0, 30));
        jPanel1.setPreferredSize(new java.awt.Dimension(400, 30));

        lblUser.setBackground(new java.awt.Color(255, 102, 255));
        lblUser.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblUser.setForeground(new java.awt.Color(255, 102, 255));
        lblUser.setText("User:");
        jPanel1.add(lblUser);

        lblUserDetail.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblUserDetail.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.add(lblUserDetail);

        lblRole.setBackground(new java.awt.Color(255, 102, 255));
        lblRole.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblRole.setForeground(new java.awt.Color(255, 102, 255));
        lblRole.setText("Role:");
        jPanel1.add(lblRole);

        lblRoleDetail.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblRoleDetail.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.add(lblRoleDetail);

        lblLoginAt.setBackground(new java.awt.Color(255, 102, 255));
        lblLoginAt.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblLoginAt.setForeground(new java.awt.Color(255, 102, 255));
        lblLoginAt.setText("Login at:");
        jPanel1.add(lblLoginAt);

        lblLoginAtDetail.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblLoginAtDetail.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.add(lblLoginAtDetail);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        mnuHome.setMnemonic('H');
        mnuHome.setText("Home");

        mniLogIn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        mniLogIn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/login.png"))); // NOI18N
        mniLogIn.setMnemonic('i');
        mniLogIn.setText("Log In");
        mniLogIn.setEnabled(false);
        mniLogIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniLogInActionPerformed(evt);
            }
        });
        mnuHome.add(mniLogIn);

        mniChangePass.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
        mniChangePass.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/change_pass.jpg"))); // NOI18N
        mniChangePass.setMnemonic('c');
        mniChangePass.setText("Change Password");
        mniChangePass.setAlignmentX(0.3F);
        mniChangePass.setEnabled(false);
        mniChangePass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniChangePassActionPerformed(evt);
            }
        });
        mnuHome.add(mniChangePass);

        mniLogOut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mniLogOut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logout.png"))); // NOI18N
        mniLogOut.setMnemonic('o');
        mniLogOut.setText("Log Out");
        mniLogOut.setEnabled(false);
        mniLogOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniLogOutActionPerformed(evt);
            }
        });
        mnuHome.add(mniLogOut);
        mnuHome.add(jSeparator1);

        mniMaAcc.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
        mniMaAcc.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Unlock.png"))); // NOI18N
        mniMaAcc.setMnemonic('a');
        mniMaAcc.setText("Manage Account");
        mniMaAcc.setEnabled(false);
        mniMaAcc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniMaAccActionPerformed(evt);
            }
        });
        mnuHome.add(mniMaAcc);

        mniConfig.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, 0));
        mniConfig.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Config.png"))); // NOI18N
        mniConfig.setMnemonic('c');
        mniConfig.setText("Connection Config");
        mniConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniConfigActionPerformed(evt);
            }
        });
        mnuHome.add(mniConfig);
        mnuHome.add(jSeparator2);

        mniQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
        mniQuit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quit.png"))); // NOI18N
        mniQuit.setMnemonic('q');
        mniQuit.setText("Quit");
        mniQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniQuitActionPerformed(evt);
            }
        });
        mnuHome.add(mniQuit);

        mbrMain.add(mnuHome);

        mnuCust.setMnemonic('u');
        mnuCust.setText("Customer");
        mnuCust.setEnabled(false);

        mniMaCust.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
        mniMaCust.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/customer.png"))); // NOI18N
        mniMaCust.setMnemonic('u');
        mniMaCust.setText("Manage Customer");
        mniMaCust.setAlignmentX(0.4F);
        mniMaCust.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniMaCustActionPerformed(evt);
            }
        });
        mnuCust.add(mniMaCust);
        mnuCust.add(jSeparator3);

        mniMaApp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        mniMaApp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/calendar.png"))); // NOI18N
        mniMaApp.setMnemonic('m');
        mniMaApp.setText("Manage Appointment");
        mniMaApp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniMaAppActionPerformed(evt);
            }
        });
        mnuCust.add(mniMaApp);

        mniSeApp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mniSeApp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Search.png"))); // NOI18N
        mniSeApp.setMnemonic('s');
        mniSeApp.setText("Search Appointment");
        mniSeApp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniSeAppActionPerformed(evt);
            }
        });
        mnuCust.add(mniSeApp);
        mnuCust.add(jSeparator4);

        mniCustDepReport.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, java.awt.event.InputEvent.ALT_MASK));
        mniCustDepReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/report.png"))); // NOI18N
        mniCustDepReport.setMnemonic('r');
        mniCustDepReport.setText("Appointment Report");
        mnuCust.add(mniCustDepReport);

        mbrMain.add(mnuCust);

        mnuSer.setMnemonic('S');
        mnuSer.setText("Service");
        mnuSer.setEnabled(false);

        mniMaCat.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        mniMaCat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/category.jpg"))); // NOI18N
        mniMaCat.setMnemonic('c');
        mniMaCat.setText("Manage Category - Service");
        mniMaCat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniMaCatActionPerformed(evt);
            }
        });
        mnuSer.add(mniMaCat);

        mniSerDeptReport.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        mniSerDeptReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/report.png"))); // NOI18N
        mniSerDeptReport.setMnemonic('r');
        mniSerDeptReport.setText("Operation Report");
        mnuSer.add(mniSerDeptReport);

        mbrMain.add(mnuSer);

        mnuPer.setMnemonic('p');
        mnuPer.setText("Personel");
        mnuPer.setEnabled(false);

        mniMaSta.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        mniMaSta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/customer.png"))); // NOI18N
        mniMaSta.setMnemonic('f');
        mniMaSta.setText("Manage Staff");
        mniMaSta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniMaStaActionPerformed(evt);
            }
        });
        mnuPer.add(mniMaSta);

        mbrMain.add(mnuPer);

        mnuCash.setMnemonic('c');
        mnuCash.setText("Cashier");
        mnuCash.setEnabled(false);

        mniMaBill.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        mniMaBill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bill.png"))); // NOI18N
        mniMaBill.setMnemonic('m');
        mniMaBill.setText("Manage Bill");
        mniMaBill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniMaBillActionPerformed(evt);
            }
        });
        mnuCash.add(mniMaBill);

        mniSeBill.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mniSeBill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Search.png"))); // NOI18N
        mniSeBill.setMnemonic('s');
        mniSeBill.setText("Search Bill");
        mniSeBill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniSeBillActionPerformed(evt);
            }
        });
        mnuCash.add(mniSeBill);
        mnuCash.add(jSeparator5);

        mniCashDeptReport.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, java.awt.event.InputEvent.ALT_MASK));
        mniCashDeptReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/report.png"))); // NOI18N
        mniCashDeptReport.setMnemonic('r');
        mniCashDeptReport.setText("Payment Report");
        mnuCash.add(mniCashDeptReport);

        mbrMain.add(mnuCash);

        mnuAbout.setMnemonic('A');
        mnuAbout.setText("About");

        mniAuthor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        mniAuthor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/author.jpg"))); // NOI18N
        mniAuthor.setText("Authors");
        mnuAbout.add(mniAuthor);

        mbrMain.add(mnuAbout);

        setJMenuBar(mbrMain);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void displayForm(String fieldName, Class obj){
        
        try {
            Field var = this.getClass().getField(fieldName);
            JInternalFrame form = (JInternalFrame)var.get(this);
            if (form == null || form.isClosed()) {
                form = (JInternalFrame)obj.getConstructor(DBConnection.class).newInstance(dc);
                var.set(this, form);
                form.setVisible(true);
                desk.add(form);
            }
            util.focusOn(form);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InstantiationException | InvocationTargetException ex) {
            Logger.getLogger(FrmHome.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }
    
    public void setText(String fieldName, String info) {
        try {
            Field var = this.getClass().getDeclaredField(fieldName);
            JLabel label = (JLabel)var.get(this); 
            label.setText(info);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
            Logger.getLogger(FrmHome.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void setEnabledJMenu(String fieldName, boolean enabled) {
        try {
            Field var = this.getClass().getDeclaredField(fieldName);
            JMenu mnu = (JMenu)var.get(this); 
            mnu.setEnabled(enabled);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
            Logger.getLogger(FrmHome.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void setEnabledJMenuItem(String fieldName, boolean enabled) {
        try {
            Field var = this.getClass().getDeclaredField(fieldName);
            JMenuItem mni = (JMenuItem)var.get(this); 
            mni.setEnabled(enabled);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
            Logger.getLogger(FrmHome.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    private void mniQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniQuitActionPerformed
        dc.disconnect();
        System.exit(0);
    }//GEN-LAST:event_mniQuitActionPerformed

    private void mniLogInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniLogInActionPerformed
        displayForm("fLogin",FrmLogin.class);
    }//GEN-LAST:event_mniLogInActionPerformed

    private void mniChangePassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniChangePassActionPerformed
        displayForm("fChangePass",FrmChangePass.class);
    }//GEN-LAST:event_mniChangePassActionPerformed

    private void mniMaAccActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniMaAccActionPerformed
        displayForm("fAccount",FrmAccount.class);
    }//GEN-LAST:event_mniMaAccActionPerformed

    private void mniConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniConfigActionPerformed
        displayForm("fConfig",FrmConfig.class);
    }//GEN-LAST:event_mniConfigActionPerformed

    private void mniMaCustActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniMaCustActionPerformed
        displayForm("fCust",FrmCustomer.class);
    }//GEN-LAST:event_mniMaCustActionPerformed

    private void mniMaAppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniMaAppActionPerformed
        displayForm("fApp",FrmAppointment.class);
    }//GEN-LAST:event_mniMaAppActionPerformed

    private void mniSeAppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniSeAppActionPerformed
        displayForm("fSearchApp",FrmSearchApp.class);
    }//GEN-LAST:event_mniSeAppActionPerformed

    private void mniMaCatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniMaCatActionPerformed
        displayForm("fCate_Ser",FrmCate_Service.class);
    }//GEN-LAST:event_mniMaCatActionPerformed

    private void mniMaStaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniMaStaActionPerformed
        displayForm("fStaff",FrmStaff.class);
    }//GEN-LAST:event_mniMaStaActionPerformed

    private void mniMaBillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniMaBillActionPerformed
        displayForm("fBill",FrmBill.class);
    }//GEN-LAST:event_mniMaBillActionPerformed

    private void mniSeBillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniSeBillActionPerformed
        displayForm("fSearchBill",FrmSearchBill.class);
    }//GEN-LAST:event_mniSeBillActionPerformed

    private void mniLogOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniLogOutActionPerformed
        logOut();
    }//GEN-LAST:event_mniLogOutActionPerformed

    public void logOut() {
        JInternalFrame[] j = desk.getAllFrames();
        
        for (int i = 0; i < j.length; i++) {
            j[i].dispose();
        }
        
        lblUserDetail.setText("");
        lblRoleDetail.setText("");
        lblLoginAtDetail.setText("");
        mniLogIn.setEnabled(true);
        mniChangePass.setEnabled(false);
        mniLogOut.setEnabled(false);
        mniMaAcc.setEnabled(false);
        mnuCust.setEnabled(false);
        mnuSer.setEnabled(false);
        mnuPer.setEnabled(false);
        mnuCash.setEnabled(false);
    }
    
    public void getCon(String fName) {
        
        if (dc != null) {
            displayForm("fLogin",FrmLogin.class);
            return;
        }
        
        try {
            FileReader fr = new FileReader(fName);
            BufferedReader br = new BufferedReader(fr);
            dc = new DBConnection(new String[] {br.readLine(),br.readLine(),br.readLine(),br.readLine(),br.readLine()});
            br.close();
            fr.close();
            
            displayForm("fLogin",FrmLogin.class);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Cannot connect to database. Please config database parameter");
            displayForm("fConfig",FrmConfig.class);
            dc = null;
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
            //for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            //    if ("Nimbus".equals(info.getName())) {
            //        javax.swing.UIManager.setLookAndFeel(info.getClassName());
            //        break;
            //    }
            //}
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmHome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmHome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmHome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmHome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmHome().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desk;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JLabel lblLoginAt;
    private javax.swing.JLabel lblLoginAtDetail;
    private javax.swing.JLabel lblRole;
    private javax.swing.JLabel lblRoleDetail;
    private javax.swing.JLabel lblUser;
    private javax.swing.JLabel lblUserDetail;
    private javax.swing.JMenuBar mbrMain;
    private javax.swing.JMenuItem mniAuthor;
    private javax.swing.JMenuItem mniCashDeptReport;
    private javax.swing.JMenuItem mniChangePass;
    private javax.swing.JMenuItem mniConfig;
    private javax.swing.JMenuItem mniCustDepReport;
    private javax.swing.JMenuItem mniLogIn;
    private javax.swing.JMenuItem mniLogOut;
    private javax.swing.JMenuItem mniMaAcc;
    private javax.swing.JMenuItem mniMaApp;
    private javax.swing.JMenuItem mniMaBill;
    private javax.swing.JMenuItem mniMaCat;
    private javax.swing.JMenuItem mniMaCust;
    private javax.swing.JMenuItem mniMaSta;
    private javax.swing.JMenuItem mniQuit;
    private javax.swing.JMenuItem mniSeApp;
    private javax.swing.JMenuItem mniSeBill;
    private javax.swing.JMenuItem mniSerDeptReport;
    private javax.swing.JMenu mnuAbout;
    private javax.swing.JMenu mnuCash;
    private javax.swing.JMenu mnuCust;
    private javax.swing.JMenu mnuHome;
    private javax.swing.JMenu mnuPer;
    private javax.swing.JMenu mnuSer;
    // End of variables declaration//GEN-END:variables
}
